package com.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo.dao.TeacherDao;
import com.demo.model.Teacher;
import com.demo.service.TeacherService;

@Service
public class TeacherServiceImpl implements TeacherService {

	@Autowired
	private TeacherDao teacherDao;

	@Override
	public int save(Teacher teacher) {
		return teacherDao.insert(teacher);
	}

	@Override
	public List<Teacher> getTeachers(String name, int pageNo, int pageSize) {
		return teacherDao.select(name, pageNo, pageSize);
	}

	@Override
	public Integer updateTeacher(Teacher teacher) {
		if (teacher.getId() != null && teacher.getId() > 0) {
			return teacherDao.update(teacher);
		}
		return teacherDao.insert(teacher);
	}

	@Override
	public Integer deleteTeacher(int id) {
		return teacherDao.delete(id);
	}

	@Override
	public Teacher getTeacherById(int id) {
		return teacherDao.selectOne(id);
	}
	
	@Override
	public int count(String name) {
		return teacherDao.count(name);
	}

}
